﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DomainDriver.CommonUtilities.Enums;
using DomainDriver.CommonUtilities.Reflectors;
using DomainDriver.DomainModeling.Constraints;
using DomainDriver.DomainModeling.DataProviders;
using DomainDriver.DomainModeling.Queries;
using DomainDriver.DomainModeling.Repositories;
using DomainDriver.DomainModeling.Example;
using DomainDriver.DomainModeling.Example.DomainObjects;
using DomainDriver.DomainModeling.GenericUnitTesting.Repositories;

namespace DomainDriver.DomainModeling.UnitTests.Repositories
{
    [TestFixture(new object[] { DataSourcePersistenceType.None })]
    [TestFixture(new object[] { DataSourcePersistenceType.File })]
    [TestFixture(new object[] { DataSourcePersistenceType.Database })]
    public class EnumerationDomainObjectRepositoryTests : RepositoryTestFixture<ExampleDomainModel, EnumerationValue, EnumerationDomainObject>
    {
        protected int m_CurrentKeyValue = int.MinValue;

        public EnumerationDomainObjectRepositoryTests(DataSourcePersistenceType persistenceType)
            : base(persistenceType)
        {
            // do nothing
        }

        protected override ExampleDomainModel CreateDomainModel(DataSourcePersistenceType persistenceType, bool buildModelWithConstraints)
        {
            ExampleDomainModel model = new ExampleDomainModel(persistenceType, buildModelWithConstraints);
            return model;
        }

        [SetUp]
        public override void SetUp()
        {
            base.SetUp();

            Array enumValues = Enum.GetValues(typeof(EnumerationValue));
            NumberOfTestInstances = enumValues.Length;
            m_CurrentKeyValue = EnumUtilities.GetMinEnumValue<EnumerationValue>();
        }

        protected override EnumerationDomainObject CreateDomainObject()
        {
            EnumerationValue currentValue = (EnumerationValue)m_CurrentKeyValue++;
            EnumerationDomainObject domainObject = new EnumerationDomainObject(currentValue);
            return domainObject;
        }

        protected override void UpdateDomainObject(EnumerationDomainObject domainObject, ref bool objectCanBeUpdated)
        {
            objectCanBeUpdated = false;
        }
    }
}